#include<iostream>
using namespace std;
#include<vector>

bool arr[301][301] = { 0 };

int arrx[4] = { -1,1,0,0 };
int arry[4] = { 0,0,-1,1 };

void getLands(vector<vector<char>>& grid,int x,int y)
{
	int length1 = grid.size();
	int length2 = grid[0].size();

	if (grid[x][y] == '1' && !arr[x][y])
	{
		grid[x][y] = '0';
		arr[x][y] = 1;
		for (int i = 0; i < 4; i++)
		{
			int x1 = x + arrx[i];
			int y1 = y + arry[i];
			if (x1>=0&&x1<length1)
			{
				if (y1 >= 0 && y1 < length2)
				{
					getLands(grid, x1, y1);
				}
			}
		}
	}
}

int numIslands(vector<vector<char>>& grid) {
	int length1 = grid.size();
	int length2 = grid[0].size();
	int number = 0;
	for (int i = 0; i < length1; i++)
	{
		for (int j = 0; j < length2; j++)
		{
			if (grid[i][j]=='1')
			{
				getLands(grid, i, j);
				number++;
			}
		}
	}
	return number;
}

int main()
{

	return 0;
}